Skip to content

feat: Graph tracking refactor — ManagedAgentGraph drives tracking for new runner shape#154

Merged
jsonbailey merged 7 commits intomainfrom
jb/aic-2174/graph-tracking-refactor
May 4, 2026
Merged

feat: Graph tracking refactor — ManagedAgentGraph drives tracking for new runner shape#154
jsonbailey merged 7 commits intomainfrom
jb/aic-2174/graph-tracking-refactor

Conversation

@jsonbailey
Copy link
Copy Markdown
Contributor

@jsonbailey jsonbailey commented Apr 28, 2026

Summary

Moves graph-level LaunchDarkly tracking from inside the runner implementations to the ManagedAgentGraph managed layer.

  • ManagedAgentGraph.run() now detects runner result type via isinstance:
    • AgentGraphRunnerResult (new shape): managed layer drives all graph-level tracking (path, duration, success/failure, total tokens) from result.metrics via the graph tracker
    • AgentGraphResult (legacy shape): tracking already occurred inside the runner; managed layer wraps the result without additional tracking
  • ManagedAgentGraph now accepts an optional graph: AgentGraphDefinition parameter used to create the graph tracker
  • LDAIClient.create_agent_graph() passes the resolved graph definition as graph=graph

Deliberate bridge pattern: The legacy detection branch exists because PR 11-openai and PR 11-langchain have not yet migrated their runners to return AgentGraphRunnerResult. Once both runners are migrated, the legacy AgentGraphResult branch becomes dead code and will be removed in PR 11-langchain's cleanup commit.

Depends on

Test plan

  • All existing tests pass (uv run pytest packages/sdk/server-ai/tests/)
  • New tests: test_managed_agent_graph_run_handles_new_shape, test_managed_agent_graph_new_shape_drives_tracking, test_managed_agent_graph_new_shape_no_graph_skips_tracking
  • Legacy tests continue to pass (AgentGraphResult path unchanged)

🤖 Generated with Claude Code


Note

Medium Risk
Changes the AgentGraphRunner.run() return type and refactors graph/node metric tracking, which may break provider implementations or alter emitted analytics events if any callers still rely on the legacy shapes/semantics.

Overview
Refactors agent-graph execution so ManagedAgentGraph now owns graph-level and per-node LaunchDarkly tracking, driven from the runner’s returned GraphMetrics (path/duration/success/token usage plus node metrics) instead of relying on provider-specific runner implementations.

Updates the public runner interface to return AgentGraphRunnerResult (with content + GraphMetrics), adjusts GraphMetricSummary to hold per-node LDAIMetricSummary values, and changes tool-call tracking summaries to accumulate calls rather than being single-assignment.

Adds/updates tests around the new managed tracking behavior and includes a new poetry.lock for server-ai.

Reviewed by Cursor Bugbot for commit 7515637. Bugbot is set up for automated code reviews on this repo. Configure here.

@jsonbailey jsonbailey force-pushed the jb/aic-2388/enrich-metrics branch from cbe2eda to 4f12618 Compare April 29, 2026 13:15
@jsonbailey jsonbailey force-pushed the jb/aic-2174/graph-tracking-refactor branch from fcbcb18 to 9286d53 Compare April 29, 2026 13:15
@jsonbailey jsonbailey force-pushed the jb/aic-2388/enrich-metrics branch from 4f12618 to 351f249 Compare April 29, 2026 13:19
@jsonbailey jsonbailey force-pushed the jb/aic-2174/graph-tracking-refactor branch from 9286d53 to 72fc13e Compare April 29, 2026 13:19
@jsonbailey jsonbailey force-pushed the jb/aic-2388/enrich-metrics branch from 351f249 to ef03235 Compare April 29, 2026 13:22
@jsonbailey jsonbailey force-pushed the jb/aic-2174/graph-tracking-refactor branch from 72fc13e to bde4f09 Compare April 29, 2026 13:22
@jsonbailey jsonbailey force-pushed the jb/aic-2388/enrich-metrics branch from ef03235 to e5ecc6a Compare April 29, 2026 13:52
@jsonbailey jsonbailey force-pushed the jb/aic-2174/graph-tracking-refactor branch from bde4f09 to c376011 Compare April 29, 2026 13:52
@jsonbailey jsonbailey force-pushed the jb/aic-2388/enrich-metrics branch from e5ecc6a to 1636446 Compare April 29, 2026 13:57
@jsonbailey jsonbailey force-pushed the jb/aic-2174/graph-tracking-refactor branch from c376011 to 7f67e4f Compare April 29, 2026 13:57
@jsonbailey jsonbailey force-pushed the jb/aic-2388/enrich-metrics branch from 1636446 to 0fae2df Compare April 29, 2026 14:38
@jsonbailey jsonbailey force-pushed the jb/aic-2174/graph-tracking-refactor branch from 7f67e4f to a89c6a2 Compare April 29, 2026 14:38
@jsonbailey jsonbailey force-pushed the jb/aic-2388/enrich-metrics branch from 0fae2df to a468a7f Compare April 29, 2026 16:33
@jsonbailey jsonbailey force-pushed the jb/aic-2174/graph-tracking-refactor branch 2 times, most recently from c69a9ff to 14cfa92 Compare April 30, 2026 14:03
@jsonbailey jsonbailey changed the base branch from jb/aic-2388/enrich-metrics to jb/aic-2388/managed-graph-result April 30, 2026 14:09
@jsonbailey jsonbailey force-pushed the jb/aic-2388/managed-graph-result branch from 0a1ee15 to 72f5a37 Compare April 30, 2026 14:22
@jsonbailey jsonbailey force-pushed the jb/aic-2174/graph-tracking-refactor branch from 14cfa92 to 1ed1a44 Compare April 30, 2026 14:23
@jsonbailey jsonbailey force-pushed the jb/aic-2388/managed-graph-result branch from 72f5a37 to 8e60f79 Compare April 30, 2026 14:44
@jsonbailey jsonbailey force-pushed the jb/aic-2174/graph-tracking-refactor branch from 1ed1a44 to f016b0d Compare April 30, 2026 14:46
@jsonbailey jsonbailey force-pushed the jb/aic-2388/managed-graph-result branch 3 times, most recently from f9e947b to 75172d8 Compare May 1, 2026 21:37
Base automatically changed from jb/aic-2388/managed-graph-result to main May 1, 2026 22:07
@jsonbailey jsonbailey force-pushed the jb/aic-2174/graph-tracking-refactor branch 3 times, most recently from 76b9580 to 7f0642e Compare May 4, 2026 14:13
@jsonbailey jsonbailey marked this pull request as ready for review May 4, 2026 15:04
@jsonbailey jsonbailey requested a review from a team as a code owner May 4, 2026 15:04
jsonbailey and others added 5 commits May 4, 2026 10:13
… new runner shape

ManagedAgentGraph.run() now detects the runner result type and dispatches
accordingly:
- AgentGraphRunnerResult (new shape): managed layer drives all graph-level
  tracking from result.metrics (path, duration, success/failure, total tokens)
  via the graph tracker. Node-level tracking from node_metrics will be wired
  once runners populate that field (PR 11-openai/langchain).
- AgentGraphResult (legacy shape): tracking already occurred inside the runner;
  managed layer wraps result without additional tracking.

ManagedAgentGraph now accepts an optional graph parameter (AgentGraphDefinition)
used to create the graph tracker. LDAIClient.create_agent_graph() passes the
resolved graph definition. This is a deliberate bridge pattern: the legacy
detection branch will be removed once both runners are migrated.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ManagedAgentGraph now expects AgentGraphRunnerResult (with GraphMetrics) from
all runners and drives graph-level and per-node LD tracking from result.metrics.
AgentGraphRunner protocol updated to return AgentGraphRunnerResult.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Aligns ManagedAgentGraph constructor with the ManagedModel and ManagedAgent
pattern: graph (AgentGraphDefinition) is now the first required parameter,
followed by the runner. Removes the Optional guard and tightens the type
annotation accordingly. Updates client.py call site and all test fixtures.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jsonbailey jsonbailey force-pushed the jb/aic-2174/graph-tracking-refactor branch from 5527667 to 8035890 Compare May 4, 2026 15:14
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8035890. Configure here.

Comment thread packages/sdk/server-ai/src/ldai/tracker.py Outdated
Comment thread packages/sdk/server-ai/src/ldai/tracker.py Outdated
@jsonbailey jsonbailey merged commit 20a5020 into main May 4, 2026
45 checks passed
@jsonbailey jsonbailey deleted the jb/aic-2174/graph-tracking-refactor branch May 4, 2026 16:56
@github-actions github-actions Bot mentioned this pull request May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants